package com.myjob.test;

import com.myjob.R;
import com.myjob.common.MyConfig;
import com.myjob.test.comm.DBHelper;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class DB_Step2 extends Activity {
	
	private DBHelper mHelper;
	private Cursor mCursor;
	private SQLiteDatabase db;

	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.test_db_step2);
	    
	    mHelper = new DBHelper(2, this, "PRODUCT.db", null, 1);
	    db = mHelper.getWritableDatabase();
	    
	    mCursor = db.rawQuery("SELECT * FROM PRODUCT", null);
	    startManagingCursor(mCursor);
	    
	    Log.i(MyConfig.DBG_LOG, "___DB_Step2 getColumnCount() : "+mCursor.getColumnCount());
	    Log.i(MyConfig.DBG_LOG, "___DB_Step2 column Name_1 : "+mCursor.getColumnName(0));
	    Log.i(MyConfig.DBG_LOG, "___DB_Step2 column Name_2 : "+mCursor.getColumnName(1));
	    Log.i(MyConfig.DBG_LOG, "___DB_Step2 column Name_3 : "+mCursor.getColumnName(3));
	    Log.i(MyConfig.DBG_LOG, "___DB_Step2 getCount() : "+mCursor.getCount());
	    
	    SimpleCursorAdapter cAdapter = null;
	    cAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, mCursor, new String[]{"NAME", "REGDATE"}, new int[]{android.R.id.text1, android.R.id.text2});
	    
	    ListView list = (ListView)findViewById(R.id.test_db_list);
	    list.setAdapter(cAdapter);
	}

	@Override
	protected void onStop() {
		super.onStop();
		Log.i(MyConfig.DBG_LOG, "DB_Step2 - DROP TABLE PRODUCE");
		db.execSQL("DROP TABLE PRODUCT");
	}
	
	

}
